package com.lyt.springboot.util.algorithm;

import java.util.ArrayList;

public class S24 {
    /*
    对dfs的简化
     */
    ArrayList<ArrayList<Integer>> result = new ArrayList<>();
    ArrayList<Integer> arrayList = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        dfs(num,0);
        return result;
    }
    //定义dfs
    public void dfs(int[] num,int depth) {
        if(depth == num.length) {
            result.add(new ArrayList<>(arrayList));
            return;
        }
        for (int i = 0; i < num.length; i++) {
            if(!arrayList.contains(num[i])) {
                arrayList.add(num[i]);
                depth++;
                dfs(num,depth);
                //
                arrayList.remove(arrayList.size()-1);
                depth--;

            }

        }

    }

    public static void main(String[] args) {
        S24 s24 = new S24();
        int[] arr = {1,3,5};
        s24.permute(arr);
    }

}
